import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
/**
 * Created by 罗天瑞 on 2016/10/29.
 */
public class ShrinkImage {
    public void ShrinkImage()
    {
        try
        {
            BufferedImage image = ImageIO.read(new File("data/wallpaper.jpg"));
            int Width = image.getWidth();
            int Height = image.getHeight();
            int NewWidth = Width/2;
            int NewHeight =Height/2;
            int[] ImageArray = new int[Width*Height];
            image.getRGB(0,0,Width,Height,ImageArray,0,Width);

            int[] NewImageArray = new int[NewWidth*NewHeight];

            for(int j=0;j<NewHeight;j++)
            {
                for(int i = 0; i < NewWidth; i++)
                {
                    NewImageArray[i+j*NewWidth] = ImageArray[2*j*Width+2*i];
                }
            }

            BufferedImage NewImage = new BufferedImage(NewWidth,NewHeight,BufferedImage.TYPE_INT_RGB);
            NewImage.setRGB(0,0,NewWidth,NewHeight,NewImageArray,0,NewWidth);
            File output = new File("data/ShrinkWallPaper.jpg");
            ImageIO.write(NewImage,"jpg",output);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
